home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / bob_espo.swf / scripts / __Packages / CenterScreen.as < prev    next >
Text File  |  2013-04-24  |  10KB  |  312 lines

  1. class CenterScreen extends State
  2. {
  3.    static var sSTATE_IDLE = "Idle";
  4.    static var sSTATE_TURNLEFT = "TurnLeft";
  5.    static var sSTATE_TURNRIGHT = "TurnRight";
  6.    static var sSTATE_MOVEFORWARD = "MoveForward";
  7.    static var sSTATE_TURN180_LEFT = "Turn180Left";
  8.    static var sSTATE_TURN180_RIGHT = "Turn180Right";
  9.    static var sSTATE_TURN180_UP = "Turn180Up";
  10.    static var sSTATE_TURN180_DOWN = "Turn180Down";
  11.    static var sSTATE_MG_BREAKWALL = "MG_BreakTheWall";
  12.    static var sSTATE_MG_JELLYFISHSWARM = "MG_JellyFishSwarm";
  13.    static var sSTATE_MG_PUSHBUS = "MG_PushTheBus";
  14.    function CenterScreen(_mcRef)
  15.    {
  16.       super(_mcRef);
  17.       this.oCurrentMinigame = null;
  18.       this.oCurrentAlgae = null;
  19.       this.oCurrentJelly = null;
  20.       this.oCurrentWall = null;
  21.       this.oInterface = new Interface(this.mcRef.mcInterface);
  22.       this.oTransition = new MinigameTransition(this.mcRef.mcTransition);
  23.       this.sNextState = "";
  24.       this.setState(CenterScreen.sSTATE_IDLE);
  25.    }
  26.    function cleanUp()
  27.    {
  28.       super.cleanUp();
  29.       if(this.oCurrentMinigame != null)
  30.       {
  31.          this.oCurrentMinigame.destroyMiniGame(true);
  32.          delete this.oCurrentMinigame;
  33.          this.oCurrentMinigame = null;
  34.       }
  35.       if(this.oCurrentAlgae != null)
  36.       {
  37.          this.oCurrentAlgae.cleanUp();
  38.          delete this.oCurrentAlgae;
  39.       }
  40.       if(this.oCurrentJelly != null)
  41.       {
  42.          this.oCurrentJelly.cleanUp();
  43.          delete this.oCurrentJelly;
  44.       }
  45.       if(this.oCurrentWall != null)
  46.       {
  47.          this.oCurrentWall.cleanUp();
  48.          delete this.oCurrentWall;
  49.       }
  50.    }
  51.    function startBreakTheWall(_oWall)
  52.    {
  53.       if(!this.isInMiniGame())
  54.       {
  55.          this.oCurrentWall = _oWall;
  56.          this.goTo(CenterScreen.sSTATE_MG_BREAKWALL);
  57.          this.setState(CenterScreen.sSTATE_IDLE);
  58.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  59.          CTRLGame.getRef().stopAnimElements();
  60.       }
  61.    }
  62.    function startJellyFishSwarm(_oJelly)
  63.    {
  64.       if(!this.isInMiniGame())
  65.       {
  66.          this.oCurrentJelly = _oJelly;
  67.          this.goTo(CenterScreen.sSTATE_MG_JELLYFISHSWARM);
  68.          this.setState(CenterScreen.sSTATE_IDLE);
  69.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  70.          CTRLGame.getRef().stopAnimElements();
  71.       }
  72.    }
  73.    function startPushTheBus(_oAlgae)
  74.    {
  75.       if(!this.isInMiniGame())
  76.       {
  77.          this.oCurrentAlgae = _oAlgae;
  78.          this.goTo(CenterScreen.sSTATE_MG_PUSHBUS);
  79.          this.setState(CenterScreen.sSTATE_IDLE);
  80.          CTRLGame.getRef().Screen.getInterface().pauseTime();
  81.          CTRLGame.getRef().stopAnimElements();
  82.       }
  83.    }
  84.    function isInMiniGame()
  85.    {
  86.       var _loc2_ = false;
  87.       if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL || (this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM || (this.sState == CenterScreen.sSTATE_MG_PUSHBUS || !this.oTransition.isInIdle())))
  88.       {
  89.          _loc2_ = true;
  90.       }
  91.       return _loc2_;
  92.    }
  93.    function manageAnim(_nNewDir, _nLastDir, _nMovement)
  94.    {
  95.       if(_nMovement == 0)
  96.       {
  97.          if(this.isSkippableState())
  98.          {
  99.             this.setState(CenterScreen.sSTATE_IDLE);
  100.          }
  101.          else
  102.          {
  103.             this.sNextState = CenterScreen.sSTATE_IDLE;
  104.          }
  105.       }
  106.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_DOWN || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_LEFT || _nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_RIGHT)))
  107.       {
  108.          if(this.isSkippableState())
  109.          {
  110.             this.setState(CenterScreen.sSTATE_MOVEFORWARD);
  111.          }
  112.          else
  113.          {
  114.             this.sNextState = CenterScreen.sSTATE_MOVEFORWARD;
  115.          }
  116.       }
  117.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_UP)
  118.       {
  119.          if(this.isSkippableState())
  120.          {
  121.             this.setState(CenterScreen.sSTATE_TURN180_DOWN);
  122.          }
  123.          else
  124.          {
  125.             this.sNextState = CenterScreen.sSTATE_TURN180_DOWN;
  126.          }
  127.       }
  128.       else if(_nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_LEFT)
  129.       {
  130.          if(this.isSkippableState())
  131.          {
  132.             this.setState(CenterScreen.sSTATE_TURN180_LEFT);
  133.          }
  134.          else
  135.          {
  136.             this.sNextState = CenterScreen.sSTATE_TURN180_LEFT;
  137.          }
  138.       }
  139.       else if(_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_RIGHT)
  140.       {
  141.          if(this.isSkippableState())
  142.          {
  143.             this.setState(CenterScreen.sSTATE_TURN180_RIGHT);
  144.          }
  145.          else
  146.          {
  147.             this.sNextState = CenterScreen.sSTATE_TURN180_RIGHT;
  148.          }
  149.       }
  150.       else if(_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_DOWN)
  151.       {
  152.          if(this.isSkippableState())
  153.          {
  154.             this.setState(CenterScreen.sSTATE_TURN180_UP);
  155.          }
  156.          else
  157.          {
  158.             this.sNextState = CenterScreen.sSTATE_TURN180_UP;
  159.          }
  160.       }
  161.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_LEFT || (_nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_RIGHT || _nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_DOWN)))
  162.       {
  163.          if(this.isSkippableState())
  164.          {
  165.             this.setState(CenterScreen.sSTATE_TURNLEFT);
  166.          }
  167.          else
  168.          {
  169.             this.sNextState = CenterScreen.sSTATE_TURNLEFT;
  170.          }
  171.       }
  172.       else if(_nNewDir == CTRLGame.nDIR_DOWN && _nLastDir == CTRLGame.nDIR_RIGHT || (_nNewDir == CTRLGame.nDIR_RIGHT && _nLastDir == CTRLGame.nDIR_UP || (_nNewDir == CTRLGame.nDIR_UP && _nLastDir == CTRLGame.nDIR_LEFT || _nNewDir == CTRLGame.nDIR_LEFT && _nLastDir == CTRLGame.nDIR_DOWN)))
  173.       {
  174.          if(this.isSkippableState())
  175.          {
  176.             this.setState(CenterScreen.sSTATE_TURNRIGHT);
  177.          }
  178.          else
  179.          {
  180.             this.sNextState = CenterScreen.sSTATE_TURNRIGHT;
  181.          }
  182.       }
  183.    }
  184.    function setState(_sState)
  185.    {
  186.       var _loc4_ = this.sState;
  187.       super.setState(_sState);
  188.       if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL)
  189.       {
  190.          this.oCurrentMinigame = new MiniGames.BTW.BreakTheWallMG(this.mcRef.mcState);
  191.       }
  192.       else if(this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM)
  193.       {
  194.          this.oCurrentMinigame = new MiniGames.JFS.JellyFishSwarmMG(this.mcRef.mcState);
  195.       }
  196.       else if(this.sState == CenterScreen.sSTATE_MG_PUSHBUS)
  197.       {
  198.          this.oCurrentMinigame = new MiniGames.PTB.PushTheBusMG(this.mcRef.mcState);
  199.       }
  200.       if(_loc4_ == CenterScreen.sSTATE_MG_BREAKWALL || (_loc4_ == CenterScreen.sSTATE_MG_JELLYFISHSWARM || _loc4_ == CenterScreen.sSTATE_MG_PUSHBUS))
  201.       {
  202.          if(this.sState == CenterScreen.sSTATE_IDLE)
  203.          {
  204.             CTRLGame.getRef().Screen.getInterface().unPauseTime();
  205.             CTRLGame.getRef().resumeAnimElements();
  206.          }
  207.       }
  208.    }
  209.    function getInterface()
  210.    {
  211.       return this.oInterface;
  212.    }
  213.    function isSkippableState()
  214.    {
  215.       var _loc2_ = false;
  216.       if(this.sState == CenterScreen.sSTATE_MOVEFORWARD || this.sState == CenterScreen.sSTATE_IDLE)
  217.       {
  218.          _loc2_ = true;
  219.       }
  220.       return _loc2_;
  221.    }
  222.    function manageEndMiniGame()
  223.    {
  224.       if(this.oCurrentMinigame.isFinished() && this.oCurrentMinigame != null)
  225.       {
  226.          this.oCurrentMinigame.destroyMiniGame();
  227.          delete this.oCurrentMinigame;
  228.          this.oCurrentMinigame = null;
  229.          if(this.sState == CenterScreen.sSTATE_MG_BREAKWALL)
  230.          {
  231.             this.oCurrentWall.cleanUp();
  232.             delete this.oCurrentWall;
  233.             this.oCurrentWall = null;
  234.          }
  235.          else if(this.sState == CenterScreen.sSTATE_MG_JELLYFISHSWARM)
  236.          {
  237.             this.oCurrentJelly.cleanUp();
  238.             delete this.oCurrentJelly;
  239.             this.oCurrentJelly = null;
  240.          }
  241.          else
  242.          {
  243.             this.oCurrentAlgae.cleanUp();
  244.             delete this.oCurrentAlgae;
  245.             this.oCurrentAlgae = null;
  246.          }
  247.          this.goTo(CenterScreen.sSTATE_IDLE);
  248.       }
  249.    }
  250.    function manageTempState()
  251.    {
  252.       if(this.stateFinished())
  253.       {
  254.          if(this.sNextState != "")
  255.          {
  256.             this.setState(this.sNextState);
  257.             this.sNextState = "";
  258.          }
  259.          else
  260.          {
  261.             this.setState(CenterScreen.sSTATE_MOVEFORWARD);
  262.          }
  263.       }
  264.    }
  265.    function goTo(_sState)
  266.    {
  267.       this.oTransition.goTo(_sState);
  268.    }
  269.    function Idle()
  270.    {
  271.    }
  272.    function MoveForward()
  273.    {
  274.    }
  275.    function TurnLeft()
  276.    {
  277.       this.manageTempState();
  278.    }
  279.    function TurnRight()
  280.    {
  281.       this.manageTempState();
  282.    }
  283.    function Turn180Left()
  284.    {
  285.       this.manageTempState();
  286.    }
  287.    function Turn180Right()
  288.    {
  289.       this.manageTempState();
  290.    }
  291.    function Turn180Up()
  292.    {
  293.       this.manageTempState();
  294.    }
  295.    function Turn180Down()
  296.    {
  297.       this.manageTempState();
  298.    }
  299.    function MG_BreakTheWall()
  300.    {
  301.       this.manageEndMiniGame();
  302.    }
  303.    function MG_JellyFishSwarm()
  304.    {
  305.       this.manageEndMiniGame();
  306.    }
  307.    function MG_PushTheBus()
  308.    {
  309.       this.manageEndMiniGame();
  310.    }
  311. }
  312.